function [vmax_v,cmax_v] = search_c(j,aini,bini,q)
%SEARCH_C returns the best choice of c and v
%for workers
amax=900;
bmax=4900;
global vfuture AMvalues BMvalues NCini crit e r b climit
            cmin=0;
            cmax=e(j)+(1+r)*aini-tax(e(j)+r*aini-q)-q;
            cg=linspace(cmin,cmax,NCini);
            afuture=e(j)+(1+r)*aini-tax(e(j)+r*aini-q)-q-cg;
            bfuture=bini*(1+r)+q;
            vtemp=uc(cg)+b*interp2(AMvalues,BMvalues,vfuture,min(afuture,amax),min(bfuture,bmax),'spline',-1);
            [vtemp_v, ctemp_g]=max(vtemp);
            cmax_v=cg(ctemp_g);
            vmax_v=vtemp_v;            
            diff=(cmax-cmin)/4;
            while diff>crit

            diff=diff/2;
          
            if ((cmax_v>cmin))
                cg=cmax_v-diff;
            afuture=e(j)+(1+r)*aini-tax(e(j)+r*aini-q)-q-cg;
            vtemp=uc(cg)+b*interp2(AMvalues,BMvalues,vfuture,min(afuture,amax),min(bfuture,bmax),'spline',-1);
                if (vtemp>vmax_v) 
                    vmax_v=vtemp;
                    cmax_v=cg;
                    continue
                end %if
            end %while internal
            if ((cmax_v<cmax))
                cg=cmax_v+diff;
            afuture=e(j)+(1+r)*aini-tax(e(j)+r*aini-q)-q-cg;
            vtemp=uc(cg)+b*interp2(AMvalues,BMvalues,vfuture,min(afuture,amax),min(bfuture,bmax),'spline',-1);
                if (vtemp>vmax_v) 
                    vmax_v=vtemp;
                    cmax_v=cg;
                end %if
            end %while internal
            end %while
end

